package views
{
	import inerface.ICommentPanel;
	
	import main.ClientConstants;
	import main.ViewSubBase;
	
	import message.CommitBackResult;
	
	import panel.comment.CommentPanel;
	
	public class CommentView extends ViewSubBase
	{
		private var _panel:ICommentPanel;
		private var shopInfo:Object;
		
		public var shopType:int = 0;                                //1餐厅，2商店，3景点内部---
		
		public function CommentView()
		{
		}
		
		public override function show():void
		{
			render();
		}
		
		public function set info(id:int):void
		{
	
		}
		
		protected override function render():void
		{
			this.registerMessageHandler(CommitBackResult.CMD,commentStarHandler);
			if(_panel == null){
				_panel = new CommentPanel;
				_panel.showType = shopType;
				_panel.comment = commentThis;
				_panel.init(view.layout.stage,view.resourceLoader,view.lang,view.uri);
				
			}
			_panel.changeData(shopInfo);
			addView(_panel);
		}
		
		private function commentStarHandler(value:CommitBackResult):void
		{
			if(value.errorno == ClientConstants.ERROR_SUCEESS)
			{
				this.layout.closeCurrent();
				view.alert.showAlert("评论成功");
			}else
			{
				view.alert.showAlert("评论失败！");
			}
		}
		
		public override function clear():void
		{
			if(_panel){
				_panel.clear();
				
				_panel = null;
				shopInfo = null;
			}
		}
		
		public override function close():void
		{
			this.cancelMessageHandler(CommitBackResult.CMD,commentStarHandler);
		}
		
		private function commentThis(content:Object):void
		{
			this.data.viewSpot.commentThis(content);
		}
	}
}